package com.sanpu.kxe.business.trade.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.business.trade.bean.BillTypeOutput;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

/**
 * Description：账单筛选类型
 * Created by 薛勇军 on 2018/8/27.
 */

public class AllClassifyAdapter extends BaseAdapter {

    private Context mContxt;

    private int selectIndex = 0;

    private List<BillTypeOutput> datas = new ArrayList<>();

    public AllClassifyAdapter(Context mContxt) {
        this.mContxt = mContxt;
    }

    public void setNotifyData(List<BillTypeOutput> datas) {
        this.datas = datas;
        this.notifyDataSetChanged();
    }

    public void setNotifyData(int selectIndex) {
        this.selectIndex = selectIndex;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (datas != null)
            return datas.size();
        return 0;
    }

    @Override
    public BillTypeOutput getItem(int position) {
        if (datas != null)
            return datas.get(position);
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContxt, R.layout.item_all_classify, null);
        }
        TextView classifyRtv = ButterKnife.findById(convertView, R.id.classifyRtv);
        BillTypeOutput retDatBean = getItem(position);
        if (retDatBean != null && !TextUtils.isEmpty(retDatBean.getName())) {
            classifyRtv.setText(retDatBean.getName());
            if (selectIndex == position) {
                classifyRtv.setTextColor(ContextCompat.getColor(mContxt, R.color.white));
                classifyRtv.setBackgroundColor(ContextCompat.getColor(mContxt, R.color.color_base));
            } else {
                classifyRtv.setTextColor(ContextCompat.getColor(mContxt, R.color.black));
                classifyRtv.setBackgroundColor(ContextCompat.getColor(mContxt, R.color.c_F5F5F5));
            }
        }
        return convertView;
    }
}
